//
//  CMDBMovieCollectionCell.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/12.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBMovieCollectionCell: CMDBBaseCollectionViewCell {

    var coverImageView : UIImageView!
    
    var movieNameLabel  : UILabel!
    
    var movieWork : CMDBWorksBean? {
        
        didSet{
            
            guard let movieWork = movieWork else {return}
            
            movieNameLabel.text = movieWork.name
            
            let urlData = movieWork.poster.dataUsingEncoding(NSUTF8StringEncoding)
            
            do {
                
                let urlDic = try NSJSONSerialization.JSONObjectWithData(urlData!, options: []) as! [String : AnyObject]
                
                
                coverImageView.loadCoverImage((urlDic["url"] as! String))
                
            }catch _ as NSError{
                printLog("fail")
            }
        }
        
    }
    
    override func setupCollectionCell() {
        super.setupCollectionCell()
        
        
    }
    
    override func buildCollectionCell() {
        super.buildCollectionCell()
        
        coverImageView       = UIImageView()
        
        coverImageView.frame = CGRect(x: 0, y: 0, width: width, height: width * 4 / 3)
        
        contentView.addSubview(coverImageView)
        
        movieNameLabel        = UILabel()
        
        movieNameLabel.font  = CMDB_16_FONT
        
        movieNameLabel.textColor = word87Color
        
        contentView.addSubview(movieNameLabel)
        
        movieNameLabel.frame = CGRect(x: 0, y: CGRectGetMaxY(coverImageView.frame), width: width, height: 20)

    }
}
